/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.core.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import pe.core.MillionFactory;
import pe.core.db.MillionDBManager;

/**
 * Web application lifecycle listener.
 *
 * @author romulogalindo
 */
@WebListener()
public class MIllionStartUpListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //iniciando...
        //levantando el hibernate
        System.out.println("Iniciando....");
        MillionFactory.home(sce.getServletContext().getInitParameter("million_home_image"));
        MillionDBManager dao = new MillionDBManager();//provee objetos de la base de datos
        try {
            MillionFactory.procesar(dao.getAnuncios());
        } catch (Exception ep) {
            System.out.println("Error al iniciar el sistema de carga de imagenes.. " + ep.getMessage());
            ep.printStackTrace();
        }
        dao.close();
        System.out.println("Listo!");

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        //destruyendo
        System.out.println("Destruyendo....");
    }
}
